package com.yz.android_baozou.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.yz.android_baozou.R;
import com.yz.android_baozou.adapter.My_FragmentPagerAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/11/2.
 */

public class RankFragment extends Fragment {
    @Bind(R.id.tablayout_fragment_Rank)
    TabLayout tablayoutFragmentRank;
    @Bind(R.id.viewPager_Rank_main)
    ViewPager viewPagerRankMain;
    private Context mContext = null;
    private String[] mArr_rank = null;
    //用来存放排行的碎片
    private List<Fragment> mList_rank = null;
    //声明VIewPager的适配器
    private My_FragmentPagerAdapter mAdapter;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = getActivity();
        mArr_rank = getResources().getStringArray(R.array.array_rank);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_rank_main, null);
        ButterKnife.bind(this, view);
        return view;
    }


    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initDatas();
        //创建适配器
        mAdapter = new My_FragmentPagerAdapter(getActivity().getSupportFragmentManager(), mArr_rank, mList_rank);
        //给ViewPager绑定适配器
        viewPagerRankMain.setAdapter(mAdapter);
        tablayoutFragmentRank.setupWithViewPager(viewPagerRankMain);
    }

    private void initDatas() {
        //初始化数据添加碎片
        mList_rank = new ArrayList<>();
        mList_rank.add(new Rank_Read_Fragment());
        mList_rank.add(new Rank_Agree_Fragment());
        mList_rank.add(new Rank_Comment_Fragment());
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
